package cool.taomu.toolkit.service.kademlia.entity;

import java.io.Serializable
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend.lib.annotations.EqualsHashCode
import org.eclipse.xtend.lib.annotations.ToString

@Accessors
@ToString
@EqualsHashCode
class KPeerNode implements Serializable, Comparable<KPeerNode> {
    String id;
    val String host;
    val int port;

    new(String host, int port) {
        this.host = host
        this.port = port
    }

    override compareTo(KPeerNode o) {
        var int hostCompare = Integer.compare(this.host.hashCode, o.host.hashCode);
        if (hostCompare != 0) {
            return hostCompare;
        }
        return Integer.compare(this.port, o.port);
    }

}
